﻿using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;

///<summary>
///EnemyChaseState
///</summary>
public class EnemyChaseState:IEnemyState
{
    private Vector3 mTargetPosition;
    public EnemyChaseState(EnemyFSMSystem fsm, ICharacter character) : base(fsm, character)
    {
        mStateID = EnemyStateID.Chase;
    }

    public override void DoBeforeEntering()
    {
        mTargetPosition = GameFacade.Instance.GetEnemyTargetPosition();
    }

    public override void Reason(List<ICharacter> targets)
    {
        //切换条件
        if (targets != null &&  targets.Count >0)
        {
            float distance = Vector3.Distance(mCharacter.Position,targets[0].Position);
            if (distance<=mCharacter.atkRange)
            {
                mFsm.PerformTransition(EnemyTransition.CanAttack);
            }
        }

    }

    public override void Act(List<ICharacter> targets)
    {
        //如果有士兵就向士兵移动  如果没有就向兵营移动
        if (targets != null && targets.Count > 0)
        {
            mCharacter.MoveTo(targets[0].Position);
        }
        else
        {
            mCharacter.MoveTo(mTargetPosition);
        }
    }
}

